package org.myy.learn.hot.finish.双指针;

public class 移动零 {
    public int[] moveZeroes(int[] nums) {
        int n = nums.length;
        int slow = 0, fast = 0;
        while (fast < n){
            if (nums[fast] != 0){
                swap(nums, slow, fast);
                slow ++;
            }
            fast++;
        }
        return nums;
    }

    private void swap(int[] nums, int slow, int fast){
        int temp = nums[slow];
        nums[slow] = nums[fast];
        nums[fast] = temp;
    }
}
